package com.zs.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Date;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/10 下午10:42
 */
public class IntermediaryInvocationHandler2 implements InvocationHandler {
    private Object target;

    public void setTarget(Object target) {
        this.target = target;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        //执行日志操作
        System.out.println("[日志] 调用方法: " + method.getName() + ", 参数: " + Arrays.toString(args)+"开始时间："+ new Date(System.currentTimeMillis()));
        Object result = method.invoke(target, args);
        //执行日志操作
        System.out.println("[日志] 调用方法: " + method.getName() + ", 参数: " + Arrays.toString(args)+"执行完成，结束时间："+ new Date(System.currentTimeMillis()));
        return result;
    }

}
